@extends('pc_admin.app')

@section('content')
<link rel="stylesheet" href="{{asset('/addons/jquery-weui-build/css/weui.min.css')}}">
<link rel="stylesheet" href="{{asset('/addons/jquery-weui-build/css/jquery-weui.css')}}">
<link rel="stylesheet" href="/css/pc-system/attendance-left.css">
<link rel="stylesheet" href="/css/pc-system/pick-colleague.css?v=2019052901">
<div class="mian-container">
    <div class="container-section pick-colleague">
        @include(('pc_sysadmin.attendance_left'))
        <div class="right-section">
            <div class="total-num weui-cells">
                <div class="weui-cell">
                    <div class="weui-cell__bd">
                        <p>已选择：<span class="select-num"></span></p>
                    </div>
                    <div class="weui-cell__ft"><a class="num-btn" href="javascript:void(0);">完成</a></div>
                </div>
            </div>
            <div id="letter" ></div>
            <div class="sort_box weui-cells weui-cells_checkbox">
                @foreach($users as $u)
                    <label class="sort_list weui-cell weui-check__label">
                        <div class="weui-cell__hd">
                            <input type="checkbox" data-id="{{$u->id}}" class="weui-check"  @if($u->is_checked == 1) checked @endif>
                            <i class="weui-icon-checked"></i>
                        </div>
                        <div class="num_logo weui-cell__hd">
                            <img class="l1" src="{{userlogo($u->id)}}" alt="">
                        </div>
                        <div class="num_name">{{$u->qw_name}}</div>
                        {{--<span class="circle-span span-reward"></span>--}}
                    </label>
                @endforeach
            </div>
            {!! csrf_field() !!}
            <input type="hidden" name="groupid" value="{{$groupid}}">
            <div class="initials">
                <ul>
                </ul>
            </div>
        </div>
    </div>
</div>
<script src="{{asset('/addons/jquery-weui-build/js/jquery-weui.min.js')}}"></script>
<script src="{{asset('/kaohe/js/jquery.charfirst.pinyin.js')}}"></script>
<script src="{{asset('/kaohe/js/sort.js')}}"></script>
<script>
    $(document).ready(function () {
        var num=0;
        $('.weui-check').each(function(){
            if($(this).prop("checked")){
                num += 1;
            }
        });
        $('.select-num').text(num);
        $('body').on('click','.weui-check',function(){    
            var clas=$(this).parent().next().find('img').attr('class')
             if ($(this).prop("checked")) {
                 $('.total-num').css('display','block');
                 $('.pick-colleague').css('padding-bottom','115px');
                 var src=$(this).parent().next().find('img').attr('src');                 
                 $('.header').append('<img class="'+clas+'" src="'+src+'">');
                 num++;
                 
             } else {            
                 $('.header .'+clas).detach();
                 num--;
             }
            if(num==0){
                //$('.total-num').css('display','none');
                $('.pick-colleague').css('padding-bottom','65px');
            }
            $('.select-num').text(num);
        })
        $('.num-btn').click(function(){
            $('.total-num').css('display','none');
             $('.pick-colleague').css('padding-bottom','65px');
            var token = $('input[name=_token]').val();
            var groupid = $('input[name=groupid]').val();
            var ids = [];
            $('.sort_box input[type="checkbox"]').each(function () {
                if ($(this).is(':checked')) {
                    ids.push($(this).attr('data-id'));
                }
            });
            $.ajax({
                'url': '/sysadmin/group/set-member?_token='+token+'&groupid='+groupid,
                'type': 'POST',
                'data': {'userid':JSON.stringify(ids)},
                error: function (request) {
                    layer.msg("网络错误");
                },
                success: function (data) {
                    if (data.status == 'success') {
                        layer.msg("操作成功");
                        setTimeout(function(){ window.location.href='/sysadmin/permission/index' }, 1000);
                    } else {
                        layer.msg(data.msg);
                    }
                },
            });
        });
    })
</script>
@endsection